﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NewFormatProject.Infrastructure.Atrributes;
using NewFormatProject.Infrastructure.Dto.Requests.Objects;
using NewFormatProject.Infrastructure.Dto.Responses;
using NewFormatProject.Server.Instances.Extends.Requests;
using NewFormatProject.Server.Interfaces;

namespace NewFormatProject.Api.Admin.Controllers
{
    [Authorize]
    [CheckLogin]
    public class RightController : BaseController
    {
        private readonly IRightServer _rightServer;
        public RightController(IRightServer rightServer) 
        {
            _rightServer = rightServer;
        }
        /// <summary>
        /// 获取权限树
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<ResponseApiDto> Tree()
        {
            return _rightServer.Tree();
        }
        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ResponseApiDto> Add(RequestSysRightsDto dto)
        {
            return _rightServer.Add(dto.ToEntity());
        }
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ResponseApiDto> Delete(RequestSysRightsDto dto)
        {
            return _rightServer.Delete(dto.ToEntity());
        }
        /// <summary>
        /// 更新权限
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ResponseApiDto> Update(RequestSysRightsDto dto)
        {
            return _rightServer.Update(dto.ToEntity());
        }
    }
}
